<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
</head>
<body>
    <div id="app">
        <input type="text" v-model="msg"><button @click="handleClick">添加</button>
        
            <!-- 遍历arr -->
            <li @click="handleDelete(item)"v-for="item of arr" >{{item}}</li>
        </ul>
    </div>
    <script>
        new Vue({
            el:"#app",
            data:{
                msg:"html",
                arr:[]
            },
            methods: {
                handleClick(){
                    let msg = this.msg;
                    //如果msg的下标等于-1则表示数组中没有这个元素
                    if(this.arr.indexOf(msg)==-1){

                        this.arr.push(msg);
                    }
                   
                },
                handleDelete(item){
                    // 根据值获取数组下标
                    let index = this.arr.indexOf(item);
                    console.log(index);
                    this.arr.splice(index,1);

                }
            }
        })
    </script>
</body>
</html>